#ifndef DS_SQUIRREL_RESOURCEMANAGER_H
#define DS_SQUIRREL_RESOURCEMANAGER_H

#include <map>
#include <string>

using namespace std;

template <class ResourceType> class ResourceManager
{
private:
	static map<string, ResourceType*> resourcePool;

public:
	static void LoadResource(string name, ResourceType* resource);
	static void UnloadResource(string name);
	static ResourceType* GetResource(string name);
};

template<class ResourceType> map<string, ResourceType*>ResourceManager<ResourceType>::resourcePool;

template<class ResourceType> void ResourceManager<ResourceType>::LoadResource(string name, ResourceType* resource)
{
	//ResourceManager<ResourceType>::resourcePool.insert(pair<string, ResourceType*>(name, resource));
	ResourceManager<ResourceType>::resourcePool[name] = resource;
}

template<class ResourceType> void ResourceManager<ResourceType>::UnloadResource(string name)
{
	ResourceType* resource = ResourceManager<ResourceType>::GetResource(name);
	ResourceManager<ResourceType>::resourcePool.erase(name);
	delete (ResourceType*)resource;
	(ResourceType*)resource = NULL;
}

template<class ResourceType> ResourceType* ResourceManager<ResourceType>::GetResource(string name)
{
	map<string, ResourceType*>::iterator i;
	i = ResourceManager<ResourceType>::resourcePool.find(name);

	if (i != ResourceManager<ResourceType>::resourcePool.end())
		return i->second;

	return NULL;
}

#endif